package com.tanhua.dubbo.api.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tanhua.domain.db.UserInfo;
import com.tanhua.dubbo.api.UserInfoApi;
import com.tanhua.dubbo.mapper.UserInfoMapper;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

// 设置超时时间
@Service(timeout = 200000)
public class UserInfoApiImpl implements UserInfoApi {
    
    @Autowired
    private UserInfoMapper userInfoMapper;
    
    @Override
    public void save(UserInfo userInfo) {
        userInfoMapper.insert(userInfo);
    }
    
    @Override
    public void update(UserInfo userInfo) {
        userInfoMapper.updateById(userInfo);
    }
    
    @Override
    public UserInfo findById(Long id) {
        return userInfoMapper.selectById(id);
    }
    
    @Override
    public IPage<UserInfo> findByPage(Integer page, Integer pagesize) {
        return userInfoMapper.selectPage(new Page<>(page, pagesize), null);
    }
    
    /**
     * 改变用户状态
     *
     * @param userId 用户id
     * @param status 用户状态 1：正常 2：冻结
     */
    @Override
    public void changeStatus(Long userId, String status) {
        //update tb_user_info set user_status=2   where id=2;
        //创建一个用户详细对象
        UserInfo userInfo = new UserInfo();
        //创建一个修改对象
        UpdateWrapper updateWrapper = new UpdateWrapper<>();
        //修改的值
        updateWrapper.set("user_status", status);
        //修改的条件
        updateWrapper.eq("id", userId);
        //修改
        userInfoMapper.update(userInfo, updateWrapper);
    }
}
